<?php
/**
 * Flea Site
 *
 * @copyright  Copyright (c) 2008 Movoin Studio (http://movoin.com)
 * @license    Apache License 2.0
 * @version    $Id: Feedback.php 133 2009-05-23 07:49:13Z movoin $
 */

class Model_Feedback
{

    var $fields;
    var $tblComments;

    function Model_Feedback()
    {
        $this->tblComments = & FLEA::getSingleton( 'Table_Comments' );
        $this->fields = array(
            'company' => '公司名称',
            'contact' => '联系人',
            'email' => '联系邮箱',
            'tel' => '公司电话',
            'fax' => '传真号码',
            'address' => '公司地址',
            'product' => '产品型号',
            'sum' => '订购数量'
        );
    }

    function setReaded($comment_id)
    {
        $this->tblComments->updateField(array(array('comment_id', $comment_id)), 'displayorder', 1);
    }

    function getMeta()
    {
        return $this->fields;
    }

    function getFeedback($comment_id, $fields='options,displayorder,created')
    {
        return $this->tblComments->find((int)$comment_id, null, $fields);
    }

    function remove($comment_id)
    {
        if($this->tblComments->removeByPkv((int)$comment_id))
            return '删除成功!';
        return '删除失败!';
    }

    function saveFeedback(&$data, $colkey)
    {
        $data['col_key'] = $colkey;
        if($this->tblComments->save($data))
            return '提交成功!';
        return '提交失败!';
    }

    /**
     * 返回表实例
     *
     */
    function &getTable()
    {
        return $this->tblComments;
    }
}
